package com.rocket.bedroom.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rocket.bedroom.dao.LoginDao;
import com.rocket.bedroom.pojo.LoginEntity;
import com.rocket.bedroom.service.ILoginService;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.Collection;

/**
 * @Author: 周毅
 * @ClassName:
 * @Description: TODO
 * @Date: Create in 20:51 2020/5/1
 * @ModifyBy:
 */
@Service
public class LoginServiceImpl extends ServiceImpl<LoginDao, LoginEntity> implements ILoginService
{

    @Override
    public LoginEntity findLoginByPhone(String phone)
    {
        Assert.notNull(phone,"phone is null");
        LambdaQueryWrapper<LoginEntity> lambdaQuery = Wrappers.<LoginEntity>lambdaQuery();
        lambdaQuery.eq(LoginEntity::getPhone, phone);
        return super.getOne(lambdaQuery);
    }
}

/*public class LoginServiceImpl extends ServiceImpl<LoginDao, LoginEntity> implements ILoginService, UserDetailsService {
//public class LoginServiceImpl extends ServiceImpl<LoginDao, LoginEntity> implements ILoginService {

    @Override
    public UserDetails loadUserByUsername(String phone) throws UsernameNotFoundException {
        //通过账号查询出数据库对象
        LambdaQueryWrapper<LoginEntity> lambdaQuery = Wrappers.lambdaQuery();
        lambdaQuery.eq(LoginEntity::getPhone, phone);
        LoginEntity login = super.getOne(lambdaQuery, true);
        if (null == login) {
            throw new UsernameNotFoundException("用户名不存在");
        }

        return User
                .withUsername(login.getPhone())
                .password(login.getLoginPassword())
                .authorities(login.getPositionId().toString())
                .build();
    }
}*/
